<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>comparison</title>
  </head>
  <body bgcolor="#FFFFFF">
    <center>Scilab operator</center>
    <div align="right">Last update : 13/06/2006</div>
    <p>
      <b>comparison</b> -   comparison, relational operators</p>
    <h3>
      <font color="blue">Calling Sequence</font>
    </h3>
    <dl>
      <dd>
        <tt>a==b</tt>
      </dd>
      <dd>
        <tt>a~=b or a&lt;&gt;b</tt>
      </dd>
      <dd>
        <tt>a&lt;b</tt>
      </dd>
      <dd>
        <tt>a&lt;=b</tt>
      </dd>
      <dd>
        <tt>a&gt;b</tt>
      </dd>
      <dd>
        <tt>a&gt;=b</tt>
      </dd>
    </dl>
    <h3>
      <font color="blue">Parameters</font>
    </h3>
    <ul>
      <li>
        <tt>
          <b>a</b>
        </tt>: any type of variable for <tt>
          <b>a==b</b>
        </tt>, <tt>
          <b>a~=b</b>
        </tt>
        <tt>
          <b>a&lt;&gt;b</b>
        </tt> equality comparisons and restricted to real floating point and integer
	    array for order related comparisons <tt>
          <b>a&lt;b</b>
        </tt>,
	    <tt>
          <b>a&lt;=b</b>
        </tt>, <tt>
          <b>a&gt;b</b>
        </tt>,<tt>
          <b>a&gt;=b</b>
        </tt>. </li>
      <li>
        <tt>
          <b>b</b>
        </tt>: any type of variable for <tt>
          <b>a==b</b>
        </tt>, <tt>
          <b>a~=b</b>
        </tt>
        <tt>
          <b>a&lt; &gt; b</b>
        </tt> equality  comparisons and restricted to
	    real floating point and integer arrays for order related comparisons
	    <tt>
          <b>a&lt;b</b>
        </tt>, <tt>
          <b>a&lt;=b</b>
        </tt>,
	    <tt>
          <b>a&gt;b</b>
        </tt>,<tt>
          <b>a&gt;=b</b>
        </tt>.</li>
    </ul>
    <h3>
      <font color="blue">Description</font>
    </h3>
    <p>Two classes of operators have to be distinguished:</p>
    <dl>
      <dd>
        <b>The equality and inequality comparisons: </b>
        <tt>
          <b>a==b</b>
        </tt>, <tt>
          <b>a~=b</b>
        </tt> (or equivalently <tt>
          <b>a&lt;&gt;b</b>
        </tt>).
	  These operators apply to any type of operands.</dd>
      <dd>
        <b>The order related comparisons: </b>
        <tt>
          <b>a&lt;b</b>
        </tt>, <tt>
          <b>a&lt;=b</b>
        </tt>,
	    <tt>
          <b>a&gt;b</b>
        </tt>,<tt>
          <b>a&gt;=b</b>
        </tt>. These operators apply
	    only to real floating point and integer arrays.</dd>
    </dl>
    <p>The semantics of the comparison operators also depend on the operands types:</p>
    <dl>
      <dd>
        <b>With array variables </b> like floating point and integer arrays, logical arrays,
	  string arrays, polynomial and rationnal arrays, handle arrays, lists... the following rules apply:<dl>
          <dd>
            <b></b>If <tt>
              <b> a</b>
            </tt> and <tt>
              <b> b</b>
            </tt> evaluates as arrays with same types
	      and identical dimensions, the comparison is performed element by
	      element and the result is an array  of booleans of the same.</dd>
          <dd>
            <b></b>If <tt>
              <b> a</b>
            </tt> and <tt>
              <b> b</b>
            </tt>  evaluates as arrays 
	      with same types, but <tt>
              <b> a</b>
            </tt> or <tt>
              <b> b</b>
            </tt> is a 1 by
	      1 array the scalar is compared with each element of the
	      other array. The result is an array of booleans of the size of
	      the non scalar operand.</dd>
          <dd>
            <b></b>In the others cases the result is the boolean <tt>
              <b> %f</b>
            </tt>
          </dd>
          <dd>
            <b></b>If the operand data types are differents but "compatible" like
	    floating points and integers a type conversion is performed before
	    the comparison.</dd>
        </dl>
      </dd>
      <dd>
        <b>With other type of operands </b> like <tt>
          <b>function</b>
        </tt>,
	<tt>
          <b>libraries</b>
        </tt>, the result is <tt>
          <b>
	    %t</b>
        </tt> if the objects are identical and <tt>
          <b> %f</b>
        </tt> in the
	  other cases.<p>Equality comparison between operands of incompatible data types
	  returns <tt>
            <b>%f</b>
          </tt>.</p>
      </dd>
    </dl>
    <h3>
      <font color="blue">Examples</font>
    </h3>
    <pre>
    
    //element wise comparisons
    (1:5)==3
    (1:5)&lt;=4 
    (1:5)&lt;=[1 4 2 3 0]
    1&lt;[]
    list(1,2,3)~=list(1,3,3)


    //object wise comparisons
    (1:10)==[4,3]
    'foo'==3
    1==[]
    list(1,2,3)==1

    isequal(list(1,2,3),1)
    isequal(1:10,1)

    //comparison with type conversion
    int32(1)==1
    int32(1)&lt;1.5
    int32(1:5)&lt;int8(3)
    p=poly(0,'s','c')
    p==0
    p/poly(1,'s','c')==0

    
  </pre>
    <h3>
      <font color="blue">See Also</font>
    </h3>
    <p>
      <a href="less.htm">
        <tt>
          <b>less</b>
        </tt>
      </a>,&nbsp;&nbsp;<a href="boolean.htm">
        <tt>
          <b>boolean</b>
        </tt>
      </a>,&nbsp;&nbsp;<a href="../elementary/isequal.htm">
        <tt>
          <b>isequal</b>
        </tt>
      </a>,&nbsp;&nbsp;</p>
  </body>
</html>
